package com.tencent.wepay.protocol.pay.request;

import java.io.Serializable;

import com.tencent.wepay.annotation.NotBlank;
import com.tencent.wepay.annotation.NotNull;
import com.tencent.wepay.annotation.Range;
import com.tencent.wepay.annotation.SignIgnore;
import com.tencent.wepay.constant.enums.FeeTypeEnum;
import com.tencent.wepay.constant.enums.LimitPayEnum;
import com.tencent.wepay.constant.enums.TradeTypeEnum;
import com.tencent.wepay.protocol.domain.XStreamDomain;
import com.tencent.wepay.util.IpUtil;
import com.tencent.wepay.util.RandomUtil;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
@XStreamAlias("xml")
public class OrderRequest extends XStreamDomain implements Serializable{
	private static final long serialVersionUID = -1359995818440540317L;
	@NotBlank(desc="公众号或应用APPID不能为空")
	@XStreamAlias("appid")
	private String appid;
	@NotBlank(desc="商户号不能为空")
	@XStreamAlias("mch_id")
	private String mchId;
	@NotBlank(desc="设备信息不能为空",relate="tradeType",value="JSAPI")
	@XStreamAlias("device_info")
	private String deviceInfo;
	@XStreamAlias("nonce_str")
	private String nonceStr=RandomUtil.uuid();
	@XStreamAlias("sign")
	@SignIgnore
	private String sign;
	@NotBlank(desc="支付描述不能为空")
	@XStreamAlias("body")
	private String body;
	@XStreamAlias("detail")
	private String detail;
	@XStreamAlias("attach")
	private String attach;
	@NotBlank("商家交易订单号不能为空")
	@XStreamAlias("out_trade_no")
	private String tradeNo;
	@XStreamAlias("fee_type")
	private FeeTypeEnum feeType=FeeTypeEnum.CNY;
	@XStreamAlias("openid")
	@NotBlank(desc="用户标识不能为空",relate="tradeType",value="JSAPI")
	private String openid;
	@XStreamAlias("time_start")
	private String startTime;
	@XStreamAlias("time_expire")
	private String expireTime;
	@XStreamAlias("goods_tag")
	private String goodsTag;
	@NotBlank(desc="接收微信支付异步通知回调地址不能为空")
	@XStreamAlias("notify_url")
	private String notifyUrl;
	@NotNull(desc="交易类型不能为空")
	@XStreamAlias("trade_type")
	private TradeTypeEnum tradeType;
	@NotBlank(desc="商品ID不能为空",relate="tradeType",value="NATIVE")
	@XStreamAlias("product_id")
	private String productId;
	@XStreamAlias("limit_pay")
	private LimitPayEnum limitPay;
	@Range(min=1,desc="金额必须大于{0}")
	@NotNull(desc="金额不能为空")
	@XStreamAlias("total_fee")
	private Integer amount;
	@NotBlank(desc="IP地址不能为空")
	@XStreamAlias("spbill_create_ip")
	private String ip=IpUtil.getLocalIp();
	@XStreamOmitField
	@SignIgnore
	@NotBlank(desc="支付密钥不能为空")
	private String key;
	public String getAppid() {
		return appid;
	}
	public void setAppid(String appid) {
		this.appid = appid;
	}
	public String getMchId() {
		return mchId;
	}
	public void setMchId(String mchId) {
		this.mchId = mchId;
	}
	public String getDeviceInfo() {
		return deviceInfo;
	}
	public void setDeviceInfo(String deviceInfo) {
		this.deviceInfo = deviceInfo;
	}
	public String getNonceStr() {
		return nonceStr;
	}
	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}
	public String getSign() {
		return sign;
	}
	public void setSign(String sign) {
		this.sign = sign;
	}
	public String getTradeNo() {
		return tradeNo;
	}
	public void setTradeNo(String tradeNo) {
		this.tradeNo = tradeNo;
	}
	public String getOpenid() {
		return openid;
	}
	public void setOpenid(String openid) {
		this.openid = openid;
	}
	
	public Integer getAmount() {
		return amount;
	}
	public void setAmount(Integer amount) {
		this.amount = amount;
	}
	
	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public String getBody() {
		return body;
	}
	public void setBody(String body) {
		this.body = body;
	}
	public String getDetail() {
		return detail;
	}
	public void setDetail(String detail) {
		this.detail = detail;
	}
	public String getAttach() {
		return attach;
	}
	public void setAttach(String attach) {
		this.attach = attach;
	}
	public FeeTypeEnum getFeeType() {
		return feeType;
	}
	public void setFeeType(FeeTypeEnum feeType) {
		this.feeType = feeType;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getExpireTime() {
		return expireTime;
	}
	public void setExpireTime(String expireTime) {
		this.expireTime = expireTime;
	}
	public String getGoodsTag() {
		return goodsTag;
	}
	public void setGoodsTag(String goodsTag) {
		this.goodsTag = goodsTag;
	}
	public String getNotifyUrl() {
		return notifyUrl;
	}
	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}
	public TradeTypeEnum getTradeType() {
		return tradeType;
	}
	public void setTradeType(TradeTypeEnum tradeType) {
		this.tradeType = tradeType;
	}
	public String getProductId() {
		return productId;
	}
	public void setProductId(String productId) {
		this.productId = productId;
	}
	public LimitPayEnum getLimitPay() {
		return limitPay;
	}
	public void setLimitPay(LimitPayEnum limitPay) {
		this.limitPay = limitPay;
	}
	@Override
	public String toXML() {
		setSign(toSign(key));
		return super.toXML();
	}
}
